package com.sms.plateform.web.tag;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.sms.plateform.common.util.Utils;
import com.sms.plateform.kernel.entity.ChannelInfo;
import com.sms.plateform.web.cache.ChannelCache;

public class ChannelInfoTag extends BaseTag{
	private static final long serialVersionUID = -7684181619622321809L;
	private String channelid = "1"; // 默认值
	private Integer col=1;
	
	public String getChannelid() {
		return channelid;
	}


	public void setChannelid(String channelid) {
		this.channelid = channelid;
	}
	

	public Integer getCol() {
		return col;
	}


	public void setCol(Integer col) {
		this.col = col;
	}

	public int doStartTag() throws JspException {
		return (SKIP_BODY);
	}
	public int doEndTag() throws JspException {
		HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
		response.setContentType("text/html; charset=utf-8");
		ChannelCache channelCache=(ChannelCache) this.getWebApplicationContext().getBean("channelCache");
		try {
			JspWriter out = pageContext.getOut();
			ChannelInfo channelInfo= channelCache.getChannelInfo(Utils.trim(channelid));
			StringBuffer sbf = new StringBuffer();
			if(col==1){
				sbf.append("<span>");
				sbf.append(channelInfo.getId());
				sbf.append("</span>");
			}else if(col==2){
				sbf.append("<span>");
				sbf.append(channelInfo.getChannelname());
				sbf.append("</span>");
			}else if(col==3){
				sbf.append("<span>");
				sbf.append(channelInfo.getChannelflag());
				sbf.append("</span>");
			}else if(col==4){
				sbf.append("<span>");
				sbf.append(channelInfo.getPrice());
				sbf.append("</span>");
			}else if(col==5){
				sbf.append("<span>");
				sbf.append(channelInfo.getIsptype());
				sbf.append("</span>");
			}else if(col==6){
				sbf.append("<span>");
				sbf.append(channelInfo.getMaxmsg());
				sbf.append("</span>");
			}else if(col==7){
				sbf.append("<span>");
				sbf.append(channelInfo.getMaxnum());
				sbf.append("</span>");
			}else if(col==8){
				sbf.append("<span>");
				sbf.append(channelInfo.getChannelcode());
				sbf.append("</span>");
			}else{
				sbf.append("<span>未知</span>");
			}
			out.write(sbf.toString());
		} catch (Exception e) {
			throw new JspException(e.getMessage());
		}
		return (EVAL_PAGE);
	}
}
